package cn.agiledata.bank.audit.dao;

import java.util.List;

import cn.agiledata.bank.hibernateBean.AuditOperandType;
import com.vnv.infrastructure.logic.IPBHibernate3BaseMgr;

/**
 * @author 马贤波
 * 
 */
public class AuditOperandTypeDaoImpl extends IPBHibernate3BaseMgr implements
        IAuditOperandTypeDao {

    public AuditOperandType getAuditOperandType(String className,
            String actionFlag) {
        String hql = "from AuditOperandType aot where aot.operandClass=? ";
        Object[] params;
        if (actionFlag == null) {
            hql += "and aot.actionFlag is null";
            params = new Object[] { className };
        } else {
            hql += "and aot.actionFlag=?";
            params = new Object[] { className, actionFlag };
        }
        List resultList = getHibernateTemplate().find(hql, params);
        return resultList.size() == 0 ? null : (AuditOperandType) resultList
                .get(0);
    }

    public AuditOperandType[] getAuditOperandTypes(boolean systemType,
            Boolean ruleUpdatable) {
        String hql = "from AuditOperandType aot where aot.systemType=?";
        Object[] params;
        if (ruleUpdatable != null) {
            hql += " and aot.ruleUpdatable=?";
            params = new Object[] { new Boolean(systemType), ruleUpdatable };
        } else {
            params = new Object[] { new Boolean(systemType) };
        }
        List resultList = getHibernateTemplate().find(hql, params);
        return (AuditOperandType[]) resultList.toArray(new AuditOperandType[0]);
    }

    public AuditOperandType getAuditOperandTypeById(long id) {
        return (AuditOperandType) getHibernateTemplate().get(
                AuditOperandType.class, new Long(id));
    }

}
